package com.dailyblue.java.boot.security.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dailyblue.java.boot.security.project.bean.Users;
import com.dailyblue.java.boot.security.project.service.PowersService;
import com.dailyblue.java.boot.security.project.service.UsersService;
import com.dailyblue.java.spring.boot.commons.util.JsonResult;
import com.dailyblue.java.spring.boot.commons.util.ResultTool;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/users")
@CrossOrigin
public class UsersController {
    @Resource
    private PowersService powersService;
    @Resource
    private UsersService usersService;

    @RequestMapping("/find")
    @PreAuthorize("hasAuthority('/users/find')")
    public JsonResult find() {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.ne("id","1");
        return ResultTool.success(usersService.list(wrapper));
    }

    @RequestMapping("/save")
    @PreAuthorize("hasAuthority('/users/save')")
    public JsonResult save() {
        return ResultTool.success("用户添加");
    }

    @RequestMapping("/delete")
    @PreAuthorize("hasAuthority('/users/delete')")
    public JsonResult delete() {
        return ResultTool.success("用户删除");
    }

    @RequestMapping("/update")
    @PreAuthorize("hasAuthority('/users/update')")
    public JsonResult update() {
        return ResultTool.success("用户修改");
    }

    @RequestMapping("/update_power")
    @PreAuthorize("hasAuthority('/users/update_power')")
    public JsonResult update_power() {
        return ResultTool.success(powersService.list());
    }
}
